package com.dingdang.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.dingdang.data.Result;
import com.dingdang.entity.TbAreas;
import com.dingdang.entity.TbCities;
import com.dingdang.entity.TbProvinces;
import com.dingdang.mapper.TbAreasMapper;
import com.dingdang.mapper.TbCitiesMapper;
import com.dingdang.mapper.TbProvincesMapper;
import com.dingdang.utils.JwtUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("location")
@Api(value = "省市县三级联动")
public class LocationController {
    @Resource
    private TbProvincesMapper tbProvincesMapper;
    @Resource
    private TbCitiesMapper tbCitiesMapper;
    @Resource
    private TbAreasMapper tbAreasMapper;
    @Resource
    private JwtUtil jwtUtil;
    @GetMapping("/getProvinces")
    @ApiOperation(value = "查寻省")
    public Result getProvinces(){
        List<TbProvinces> tbProvinces = tbProvincesMapper.selectList(null);
        return Result.ok().setData(tbProvinces);
    }
    @GetMapping ("/getCities")
    @ApiOperation(value = "查询市")
    @ApiImplicitParam(name = "provinceid",value = "省级id",paramType = "path",required = true)
    public Result getCities(@RequestParam("provinceid") String provinceid){
        QueryWrapper wrapper = new QueryWrapper<TbCities>();
        wrapper.like("provinceid",provinceid);
        List<TbCities> tbCitieslist = tbCitiesMapper.selectList(wrapper);
        return Result.ok().setData(tbCitieslist);
    }
    @GetMapping("/getAreas/{cityid}")
    @ApiOperation(value = "查询县")
    @ApiImplicitParam(name = "cityid",value = "市级id",paramType = "path",required = true)
    public Result getAreas(@PathVariable("cityid")String cityid){
        QueryWrapper wrapper = new QueryWrapper<TbAreas>();
      wrapper.like("cityid",cityid);
        List<TbAreas> areasList = tbAreasMapper.selectList(wrapper);
        return Result.ok().setData(areasList);
    }


}
